#include "Model.h"

Model::Model() {
	cpxenv = NULL;
	cpxprob = NULL;
	problem = NULL;
	ready = false;
}

Model::~Model() {
	if (cpxprob != NULL)
		CPXfreeprob(cpxenv, &cpxprob);

	if (cpxenv != NULL)
		CPXcloseCPLEX(&cpxenv);
}

bool Model::create( Problem *problem ) throw (Exception) {
	int status;

	this->problem = problem;
	cpxenv = CPXopenCPLEX( &status );
	if (status) {
		char msg[1024];
		CPXgeterrorstring( cpxenv, status, msg );
		throw Exception(msg);
	}

	cpxprob = CPXcreateprob( cpxenv, &status, problem->getName() );
	if (status) {
		char msg[1024];
		CPXgeterrorstring( cpxenv, status, msg );
		throw Exception(msg);
	}
	return true;
}